package cn.git.post;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;

import java.util.Collections;
import java.util.List;

/**
 * @description: http发送信息测试
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2024-09-23
 */
public class HttpTest {

    public static void main(String[] args) {
        testFormPost();
    }

    /**
     * 表单提交
     */
    private static void testFormPost() {
        // 设置请求list参数信息
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("endDateId", "0");
        jsonParam.put("accountName", "沈阳农村商业银行股份有限公司沈河支行营业部");
        jsonParam.put("accountNo", "100612010110639766");
        jsonParam.put("startDateId", "0");

        List<JSONObject> postParamList = Collections.singletonList(jsonParam);

        // 设置请求体
        HttpRequest formRequest = HttpRequest.post("http://3.1.13.183:80/c4c3/account/common/getToken")
                .form("projectNo", "MCON202408020000002")
                .form("entityName", "贷款申请")
                .form("userId", "101013")
                .form("userName", "吴涛")
                .form("orgCode", "1006")
                .form("brNo", "6931")
                .form("entityId", "20372440842")
                .form("businessStartDateId", "20190108")
                .form("ecmBusinessNo", "MCON202408020000002")
                .form("ecmObjType", "FRDKSQ")
                .form("ecmFileType", "13002")
                // 复杂对象
                .form("entityBankAccounts", JSONObject.toJSONString(postParamList))
                .form("appId", "corporate_app")
                .form("role", "VIEWER")
                .form("analysisType", "0")
                .form("appSecretCode", "MCON202408020000002_贷款申请_cB89iuePDx7");

        // 60秒超时
        formRequest.setConnectionTimeout(6 * 1000);
        // 设置请求头
        formRequest.contentType("application/x-www-form-urlencoded");

        // 获取响应结果信息
        String body = formRequest.execute().body();
        System.out.println(JSONObject.toJSONString(body));
    }


}
